/*
 * frmStudent.java
 *
 * Created on April 28, 2010, 5:30 PM
 */
package GUI;

import Entity.Student;
import Interact.Students;
import Validate_Connect.CheckForm;
import Validate_Connect.DataInteraction;
import Validate_Connect.GUIInteraction;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author  Shinichi
 */
public class frmStudent extends javax.swing.JInternalFrame {

    /** Creates new form frmStudent */
    public frmStudent() {
        initComponents();
        refresh();
        GUIInteraction.readToCombo("select * from tblClass", _cboclass, "ClassName");

        _rdomale.setSelected(true);
        _txtstudentName.requestFocus();

        _txtStudentID.setEditable(false);
        _txtaddress.setEditable(false);
        _txtbirthday.setEditable(false);
        _txtemail.setEditable(false);
        _txtidentityCard.setEditable(false);
        _txtmobileNum.setEditable(false);
        _txtphoneNum.setEditable(false);
        _txtsearch.setEditable(true);
        _txtstudentName.setEditable(false);
        _btnreset.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        _txtstudentName = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        _txtbirthday = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        _txtaddress = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        _txtphoneNum = new javax.swing.JTextField();
        _txtmobileNum = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        _rdomale = new javax.swing.JRadioButton();
        _rdofemale = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        _txtidentityCard = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        _txtemail = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        _cboclass = new javax.swing.JComboBox();
        _lblerr = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        _txtStudentID = new javax.swing.JTextField();
        _btnaddNew = new javax.swing.JButton();
        _btnreset = new javax.swing.JButton();
        _btnupdate = new javax.swing.JButton();
        _btndelete = new javax.swing.JButton();
        _btnprint = new javax.swing.JButton();
        _btnclose = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        _tblStudent = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false;   //Disallow the editing of any cell
            }
        };
        _tblStudent.getTableHeader().setReorderingAllowed(false);
        jLabel11 = new javax.swing.JLabel();
        _txtsearch = new javax.swing.JTextField();
        _cbochoice = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("AITSM - Management Student");

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Information"));

        jLabel1.setText("Student Name:");

        jLabel5.setText("Birthday:");

        jLabel2.setText("Address:");

        jLabel3.setText("Phone Num:");

        jLabel4.setText("Mobile Num:");

        jLabel13.setText("Gender:");

        _rdomale.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(_rdomale);
        _rdomale.setText("Male");

        _rdofemale.setBackground(new java.awt.Color(255, 255, 255));
        buttonGroup1.add(_rdofemale);
        _rdofemale.setText("Female");

        jLabel8.setText("Identity Card:");

        jLabel7.setText("Email:");

        jLabel9.setText("Class ID:");

        _lblerr.setFont(new java.awt.Font("Tahoma", 1, 11));
        _lblerr.setForeground(new java.awt.Color(255, 0, 0));

        jLabel12.setText("Student ID:");

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel8)
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(90, 90, 90)
                        .add(_txtidentityCard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 146, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel5)
                            .add(jLabel2)
                            .add(jLabel4)
                            .add(jLabel12))
                        .add(32, 32, 32)
                        .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel5Layout.createSequentialGroup()
                                .add(_txtbirthday, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 122, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(121, 121, 121)
                                .add(jLabel13)
                                .add(7, 7, 7)
                                .add(_rdomale)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(_rdofemale))
                            .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(_txtaddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 520, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(jPanel5Layout.createSequentialGroup()
                                    .add(_txtStudentID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(jLabel1)
                                    .add(18, 18, 18)
                                    .add(_txtstudentName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 225, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(jPanel5Layout.createSequentialGroup()
                                .add(_txtmobileNum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 125, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(86, 86, 86)
                                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel3)
                                    .add(jLabel9))
                                .add(32, 32, 32)
                                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(_cboclass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 114, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(_txtphoneNum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 124, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                    .add(jPanel5Layout.createSequentialGroup()
                        .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel7)
                            .add(jPanel5Layout.createSequentialGroup()
                                .add(90, 90, 90)
                                .add(_txtemail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 231, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(39, 39, 39)
                        .add(_lblerr, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(6, 6, 6)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(_txtstudentName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel12)
                    .add(_txtStudentID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(_rdomale)
                    .add(jLabel13)
                    .add(_rdofemale)
                    .add(_txtbirthday, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(_txtaddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(_txtphoneNum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4)
                    .add(_txtmobileNum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel8)
                    .add(_txtidentityCard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9)
                    .add(_cboclass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(_txtemail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(_lblerr))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        _btnaddNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/list_add2.png"))); // NOI18N
        _btnaddNew.setText("Add New");
        _btnaddNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnaddNewActionPerformed(evt);
            }
        });

        _btnreset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/reset2.png"))); // NOI18N
        _btnreset.setText("Reset");
        _btnreset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnresetActionPerformed(evt);
            }
        });

        _btnupdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/update2.png"))); // NOI18N
        _btnupdate.setText("Update");
        _btnupdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnupdateActionPerformed(evt);
            }
        });

        _btndelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        _btndelete.setText("Delete");
        _btndelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btndeleteActionPerformed(evt);
            }
        });

        _btnprint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/printer2.png"))); // NOI18N
        _btnprint.setText("Print");
        _btnprint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnprintActionPerformed(evt);
            }
        });

        _btnclose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Logout16x16.png"))); // NOI18N
        _btnclose.setText("Close");
        _btnclose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btncloseActionPerformed(evt);
            }
        });

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("List"));

        _tblStudent.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        _tblStudent.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                _tblStudentMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(_tblStudent);

        jLabel11.setText("Search:");

        _txtsearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                _txtsearchKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                _txtsearchKeyReleased(evt);
            }
        });

        _cbochoice.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "By ID", "By Name", "By Address" }));

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel11)
                .add(18, 18, 18)
                .add(_txtsearch, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(_cbochoice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 662, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(_txtsearch, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(_cbochoice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 162, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        jPanel1.setBackground(new java.awt.Color(0, 153, 153));

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 26)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Student");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(285, 285, 285)
                .add(jLabel6)
                .addContainerGap(319, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jLabel6)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(_btnaddNew, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(_btnreset, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(_btnupdate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(_btndelete, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(_btnprint, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(_btnclose, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 59, Short.MAX_VALUE))
                    .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(_btnclose)
                    .add(_btnprint)
                    .add(_btnaddNew)
                    .add(_btnreset)
                    .add(_btnupdate)
                    .add(_btndelete))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void _tblStudentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event__tblStudentMouseClicked
    int i = _tblStudent.getSelectedRow();
    _txtStudentID.setText(String.valueOf(_tblStudent.getValueAt(i, 0)));
    _txtstudentName.setText(String.valueOf(_tblStudent.getValueAt(i, 1)));
    _txtphoneNum.setText(String.valueOf(_tblStudent.getValueAt(i, 2)));
    _txtmobileNum.setText(String.valueOf(_tblStudent.getValueAt(i, 3)));
    _txtbirthday.setText(String.valueOf(_tblStudent.getValueAt(i, 4)));
    Object _gender = _tblStudent.getValueAt(i, 5);
    if (_gender.equals("1")) {
        _rdomale.setSelected(true);
    } else {
        _rdofemale.setSelected(true);
    }
    _txtaddress.setText(String.valueOf(_tblStudent.getValueAt(i, 6)));
    _txtemail.setText(String.valueOf(_tblStudent.getValueAt(i, 7)));
    _txtidentityCard.setText(String.valueOf(_tblStudent.getValueAt(i, 8)));
    _cboclass.setSelectedItem(String.valueOf(_tblStudent.getValueAt(i, 9)));
    _btnreset.setEnabled(true);
    _btndelete.setEnabled(true);
    _btnupdate.setEnabled(true);
    _btnprint.setEnabled(true);
    _btnclose.setEnabled(true);
    _txtStudentID.setEditable(false);
    _txtaddress.setEditable(false);
    _txtbirthday.setEditable(false);
    _txtemail.setEditable(false);
    _txtidentityCard.setEditable(false);
    _txtmobileNum.setEditable(false);
    _txtphoneNum.setEditable(false);
    _txtsearch.setEditable(true);
    if (_btnaddNew.getText().equals("Save")) {
        _btnaddNew.setText("Add New");
    }
    if (_btnupdate.getText().equals("Save")) {
        _btnupdate.setText("Update");
    }
    _btnaddNew.setEnabled(true);
}//GEN-LAST:event__tblStudentMouseClicked

private void _txtsearchKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event__txtsearchKeyPressed
// TODO add your handling code here:

//        if(_cbochoice.getSelectedItem().toString().equals("By ID")){
//            if(evt.isActionKey()){
//                searchByID();
//            }
//        }
//        if(_cbochoice.getSelectedItem().toString().equals("By Name")){
//            if(evt.isActionKey()){
//            searchByName();
//        }
//        }
}//GEN-LAST:event__txtsearchKeyPressed

private void _txtsearchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event__txtsearchKeyReleased
    if (_cbochoice.getSelectedItem().equals("By ID")) {
        searchByID();
    } else if (_cbochoice.getSelectedItem().equals("By Name")) {
        searchByName();
    } else if (_cbochoice.getSelectedItem().equals("By Address")) {
        searchByAddress();
    }
}//GEN-LAST:event__txtsearchKeyReleased

private void _btnaddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnaddNewActionPerformed
    if (_btnaddNew.getText().equals("Add New")) {
        resetForm();
        _txtStudentID.setEditable(true);
        _txtaddress.setEditable(true);
        _txtbirthday.setEditable(true);
        _txtemail.setEditable(true);
        _txtidentityCard.setEditable(true);
        _txtmobileNum.setEditable(true);
        _txtphoneNum.setEditable(true);
        _txtsearch.setEditable(true);
        _txtstudentName.setEditable(true);
        _btnaddNew.setText("Save");
        _txtStudentID.requestFocus();
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(false);
    } else {
        if (!validateForm()) {
            return;
        }
        Entity.Student _std = new Student();
        _std.set_StudentID(_txtStudentID.getText());
        _std.set_FullName(_txtstudentName.getText());
        _std.set_Birthday(_txtbirthday.getText());
        _std.set_Address(_txtaddress.getText());
        _std.set_MobileNum(_txtmobileNum.getText());
        _std.set_PhoneNum(_txtphoneNum.getText());
        _std.set_IdentityCard(_txtidentityCard.getText());
        _std.set_Email(_txtemail.getText());
        if (_rdomale.isSelected()) {
            _std.set_Gender(true);
        } else {
            _std.set_Gender(false);
        }
        String code = DataInteraction.getCodeString("tblClass", "ClassName", _cboclass.getSelectedItem().toString(), "ClassID");
        _std.set_ClassID(code);
        Interact.Students.insertStudent(_std);
        JOptionPane.showMessageDialog(null, "Insert succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        _lblerr.setText("");
        refresh();
        resetForm();
        _txtStudentID.setEditable(false);
        _txtaddress.setEditable(false);
        _txtbirthday.setEditable(false);
        _txtemail.setEditable(false);
        _txtidentityCard.setEditable(false);
        _txtmobileNum.setEditable(false);
        _txtphoneNum.setEditable(false);
        _txtsearch.setEditable(true);
        _txtstudentName.setEditable(false);
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(true);
        _btnaddNew.setText("Add New");
    }


}//GEN-LAST:event__btnaddNewActionPerformed

private void _btnresetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnresetActionPerformed
    resetForm();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btnresetActionPerformed

private void _btnupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnupdateActionPerformed
    if (_btnupdate.getText().equals("Update")) {
        _txtStudentID.setEditable(true);
        _txtaddress.setEditable(true);
        _txtbirthday.setEditable(true);
        _txtemail.setEditable(true);
        _txtidentityCard.setEditable(true);
        _txtmobileNum.setEditable(true);
        _txtphoneNum.setEditable(true);
        _txtsearch.setEditable(true);
        _btnaddNew.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setText("Save");
        _txtStudentID.requestFocus();
    } else {
        boolean _gender;
        if (_rdomale.isSelected()) {
            _gender = true;
        } else {
            _gender = false;
        }
        String code = DataInteraction.getCodeString("tblClass", "ClassName", _cboclass.getSelectedItem().toString(), "ClassID");
        Entity.Student std = new Student(String.valueOf(_txtStudentID.getText()),
                _txtstudentName.getText(),
                _txtphoneNum.getText(),
                _txtmobileNum.getText(),
                _txtbirthday.getText(),
                _gender,
                _txtaddress.getText(),
                _txtemail.getText(),
                _txtidentityCard.getText(), code);
        Interact.Students.updateStudent(std);
        _lblerr.setText("");
        resetForm();
        refresh();
        _txtStudentID.setEditable(false);
        _txtaddress.setEditable(false);
        _txtbirthday.setEditable(false);
        _txtemail.setEditable(false);
        _txtidentityCard.setEditable(false);
        _txtmobileNum.setEditable(false);
        _txtphoneNum.setEditable(false);
        _txtsearch.setEditable(true);
        _btnaddNew.setEnabled(true);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnupdate.setText("Update");
    }


}//GEN-LAST:event__btnupdateActionPerformed

private void _btndeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btndeleteActionPerformed
    String _id = _txtStudentID.getText();
    int i = JOptionPane.showConfirmDialog(null, "Do you want to delete " + _txtstudentName.getText(), "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (i == 0) {
        Students.deleteStudent(_id);
    }        
    resetForm();
    refresh();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btndeleteActionPerformed

private void _btnprintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnprintActionPerformed
    ConnectDB.ConnectDB.runReport("src\\Report\\reportStudentList.jasper");
}//GEN-LAST:event__btnprintActionPerformed

private void _btncloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btncloseActionPerformed
    int i = JOptionPane.showConfirmDialog(null, "Do you want to exit?", "Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (i == 0) {
        this.dispose();
    }
}//GEN-LAST:event__btncloseActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _btnaddNew;
    private javax.swing.JButton _btnclose;
    private javax.swing.JButton _btndelete;
    private javax.swing.JButton _btnprint;
    private javax.swing.JButton _btnreset;
    private javax.swing.JButton _btnupdate;
    private javax.swing.JComboBox _cbochoice;
    private javax.swing.JComboBox _cboclass;
    private javax.swing.JLabel _lblerr;
    private javax.swing.JRadioButton _rdofemale;
    private javax.swing.JRadioButton _rdomale;
    private javax.swing.JTable _tblStudent;
    private javax.swing.JTextField _txtStudentID;
    private javax.swing.JTextField _txtaddress;
    private javax.swing.JTextField _txtbirthday;
    private javax.swing.JTextField _txtemail;
    private javax.swing.JTextField _txtidentityCard;
    private javax.swing.JTextField _txtmobileNum;
    private javax.swing.JTextField _txtphoneNum;
    private javax.swing.JTextField _txtsearch;
    private javax.swing.JTextField _txtstudentName;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane4;
    // End of variables declaration//GEN-END:variables

    public void resetForm() {
        _txtStudentID.setText("");
        _txtstudentName.setText("");
        _txtbirthday.setText("");
        _txtaddress.setText("");
        _txtmobileNum.setText("");
        _txtphoneNum.setText("");
        _txtidentityCard.setText("");
        _txtemail.setText("");
    }

    public boolean validateForm() {
        if (!CheckForm.isEmpty(_txtStudentID.getText())) {
            _lblerr.setText("Please Enter Student Id");
            _txtStudentID.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtstudentName.getText())) {
            _lblerr.setText("Please Enter Student Name");
            _txtstudentName.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtbirthday.getText())) {
            _lblerr.setText("Please Enter Birthday");
            _txtbirthday.requestFocus();
            return false;
        }
        if (!CheckForm.validateDate(_txtbirthday.getText())) {
            _lblerr.setText("Birthday is not validate");
            _txtbirthday.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtaddress.getText())) {
            _lblerr.setText("Please Enter Address");
            _txtaddress.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtmobileNum.getText())) {
            _lblerr.setText("Please Enter Mobile Num");
            _txtmobileNum.requestFocus();
            return false;
        }
        if (!CheckForm.checkPhoneNumber(_txtmobileNum.getText())) {
            _lblerr.setText("Mobile Num is not validate");
            _txtmobileNum.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtidentityCard.getText())) {
            _lblerr.setText("Please Enter Identity Card");
            _txtidentityCard.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtemail.getText())) {
            _lblerr.setText("Please Enter Email");
            _txtemail.requestFocus();
            return false;
        }
        if (!CheckForm.checkEmail(_txtemail.getText())) {
            _lblerr.setText("Email is not validate");
            _txtemail.requestFocus();
            return false;
        }
        if (!GUIInteraction.checkDuplicateID(_txtStudentID.getText(), "select * from tblStudents", "StudentID")) {
            _lblerr.setText("Student Id is duplicate");
            _txtStudentID.requestFocus();
            return false;
        }
        return true;
    }

    public void refresh() {
        try {
            GUIInteraction.readToTable("select std.StudentID, std.FullName, std.PhoneNum, std.MobileNum, convert(char(10),std.Birthday,101) , std.Gender, std.Address, std.Email, std.IdentityCard, cls.ClassName from tblStudents std, tblClass cls where cls.ClassID = std.ClassID", _tblStudent);
        } catch (SQLException ex) {
            Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void searchByID() {
        String _str = _txtsearch.getText();
        String _sql = "";
        if (_str.equals("")) {
            _sql = "select * from tblStudents";
        } else {
            _sql = "select std.StudentID, std.FullName, std.PhoneNum, std.MobileNum, convert(char(10),std.Birthday,101), std.Gender, std.Address, std.Email, std.IdentityCard, cls.ClassName from tblStudents std, tblClass cls where cls.ClassID = std.ClassID and StudentID like '%" + _str + "%'";
        }
        try {
            GUIInteraction.readToTable(_sql, _tblStudent);
        } catch (SQLException ex) {
            Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void searchByName() {
        String _str = _txtsearch.getText();
        String _sql = "";
        if (_str.equals("")) {
            _sql = "select * from tblStudents";
        } else {
            _sql = "select std.StudentID, std.FullName, std.PhoneNum, std.MobileNum, convert(char(10),std.Birthday,101), std.Gender, std.Address, std.Email, std.IdentityCard, cls.ClassName from tblStudents std, tblClass cls where cls.ClassID = std.ClassID and FullName like '%" + _str + "%'";
        }
        try {
            GUIInteraction.readToTable(_sql, _tblStudent);
        } catch (SQLException ex) {
            Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void searchByAddress() {
        String _str = _txtsearch.getText();
        String _sql = "";
        if (_str.equals("")) {
            _sql = "select * from tblStudents";
        } else {
            _sql = "select std.StudentID, std.FullName, std.PhoneNum, std.MobileNum, convert(char(10),std.Birthday,101), std.Gender, std.Address, std.Email, std.IdentityCard, cls.ClassName from tblStudents std, tblClass cls where cls.ClassID = std.ClassID and Address like '%" + _str + "%'";
        }
        try {
            GUIInteraction.readToTable(_sql, _tblStudent);
        } catch (SQLException ex) {
            Logger.getLogger(frmStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
